package com.example.smartcity_ikun3.ui.home.adapter

import android.content.Intent
import android.text.Layout
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.smartcity_ikun3.R
import com.example.smartcity_ikun3.logic.util.Util.guide
import com.example.smartcity_ikun3.logic.util.Util.show
import com.example.smartcity_ikun3.ui.home.activity.more.PhoneActivity
import com.example.smartcity_ikun3.ui.home.model.MoreEntity

class ReAdapterMore (
    val data: List<MoreEntity>
) : RecyclerView.Adapter<ReAdapterMore.ViewHolder>(){
    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
        val setImg = view.findViewById<ImageView>(R.id.homeMoreImageView)
        val setTv = view.findViewById<TextView>(R.id.homeMoreTitle)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val root = LayoutInflater.from(parent.context).inflate(R.layout.re_home_more, parent, false)
        val view = ViewHolder(root)

        view.itemView.setOnClickListener {
            if (view.setTv.text == "手机话费") parent.context.startActivity(Intent(parent.context, PhoneActivity::class.java))
        }

        return view
    }

    override fun getItemCount(): Int = data.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val list = data[position]
        guide(list.ImageView, holder.setImg)
        holder.setTv.text = list.Title
    }


}